<?php
    session_start();
    require_once 'public/includes/functions.php';
    require_once 'models/submit.php';
    
    class PostController extends functions {
        
        var $submitTBL = null;
        var $row = null;
        var $infoSubmitTBL = array();
        function __construct(){
            if(empty($_SESSION['name'])){
                echo '<script language="javascript">
                        alert("Vui lòng đăng nhập để vào trang Admin");
                        document.location="index.php";
                    </script>';
            }
            $this->submitTBL = new Submit_Model();            
        }
        
        public function listAction(){
            $res = $this->submitTBL->ExecuteSQL("select * from submit");
            $this->row = mysql_num_rows($res);
            $stt = 0;
            while($rs = mysql_fetch_assoc($res)){
                $stt++;                                
                $this->infoSubmitTBL[] = array(
                    'stt'       =>  $stt,
                    'id'        =>  $rs['id'],
                    'ten'       =>  $rs['ten'],
                    'email'     =>  $rs['email'],
                    'chude'     =>  $rs['chude'],
                    'noidung'   =>  $rs['noidung'],
                    'ngaypost'  =>  $rs['ngaypost']
                );
            }
        }
        
        public function deleteAtion(){
            if(isset($_GET['action']) && strtolower($_GET['action']=='delete')){
                $id = isset($_GET['id']) ? $_GET['id'] : '';               
                $this->submitTBL->ExecuteSQL("delete from submit where ID ='".$id."'");
                
            }elseif(isset($_POST['deleteall']) && !empty($_POST['check'])){
                $arr_del = $_POST['check'];
                for($i=0; $i<count($arr_del); $i++){
                    $this->submitTBL->ExecuteSQL("delete from submit where ID ='".$arr_del[$i]."'");
                }
            }
        }
        
        public function addAction(){
            
        }
    }
    
    //action
    $post = new PostController();
    //
    //xu ly xoa thong tin
    if((isset($_GET['action']) && strtolower($_GET['action']=='delete')) 
            || isset($_POST['deleteall'])){        
        $post->deleteAtion();
    }
    
    $post->listAction();
    $post->show('poster');
    
?>